﻿using UnityEngine;
using System.Collections;

public class Fade : MonoBehaviour {

	public Color start_color;
	public Color end_color;

	public float delay = 1f;
	public float speed = 1f;
	float t = 0f;

	public bool nextlevel = false;
	public bool firstone = false;

	void Update () {

		delay -= Time.deltaTime;


		if (delay <= 0f) {
		
			t += Time.deltaTime / speed;

			float per = t / speed;

			renderer.material.color =
			Color.Lerp (start_color, end_color, per);
		
			//hommat tehty
			if (per >= 1f) {
				if (nextlevel == true)
					Application.LoadLevel (Application.loadedLevel + 1);

				this.enabled = false;
			}
		} 
		else 
		{
			//käytetään starttiväriä
			// kun efekti ei ole vielä alkanut

			renderer.material.color = start_color;
		}
	
	}
}
